import { addOrder, findAllOrder, delOrder } from '@/apis/orderAPI'
import { orderModel } from '@/types/model'
import { ref } from 'vue'

export default () => {
  const order = ref<orderModel>()
  const orders = ref<orderModel[]>([])

  // 添加方向
  const add = async (data: orderModel) => {
    await addOrder(data)
  }

  /**
   * 获取所有的Order
   * @param args 查询参数
   */
  async function all(args = {}) {
    const { data } = await findAllOrder(args)
    orders.value = data
  }

  async function del(id: number) {
    await delOrder(id)
  }

  return { add, all, del, order, orders }
}
